
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 07/26/2011 14:04:45
-- Generated from EDMX file: C:\Users\fal\Documents\Visual Studio 2010\Projects\MyBet\my-phoenix-project\MyBet.Web\DAL\MyBet.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [aspnetdb];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_Comments_aspnet_Users]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Comments] DROP CONSTRAINT [FK_Comments_aspnet_Users];
GO
IF OBJECT_ID(N'[dbo].[FK_Contests_Championships]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Contests] DROP CONSTRAINT [FK_Contests_Championships];
GO
IF OBJECT_ID(N'[dbo].[FK_Contests_Seasons]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Contests] DROP CONSTRAINT [FK_Contests_Seasons];
GO
IF OBJECT_ID(N'[dbo].[FK_CustomContest_aspnet_Membership]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CustomContest] DROP CONSTRAINT [FK_CustomContest_aspnet_Membership];
GO
IF OBJECT_ID(N'[dbo].[FK_CustomContestLinks_Contests]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CustomContestLinks] DROP CONSTRAINT [FK_CustomContestLinks_Contests];
GO
IF OBJECT_ID(N'[dbo].[FK_CustomContestLinks_CustomContest]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CustomContestLinks] DROP CONSTRAINT [FK_CustomContestLinks_CustomContest];
GO
IF OBJECT_ID(N'[dbo].[FK_CustomContestSettings_CustomContest]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CustomContestSettings] DROP CONSTRAINT [FK_CustomContestSettings_CustomContest];
GO
IF OBJECT_ID(N'[dbo].[FK_CustomContestSettings_SettingsParameters]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CustomContestSettings] DROP CONSTRAINT [FK_CustomContestSettings_SettingsParameters];
GO
IF OBJECT_ID(N'[dbo].[FK_Events_Contests]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Events] DROP CONSTRAINT [FK_Events_Contests];
GO
IF OBJECT_ID(N'[dbo].[FK_EventScores_aspnet_Users]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EventScores] DROP CONSTRAINT [FK_EventScores_aspnet_Users];
GO
IF OBJECT_ID(N'[dbo].[FK_EventScores_Events]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EventScores] DROP CONSTRAINT [FK_EventScores_Events];
GO
IF OBJECT_ID(N'[dbo].[FK_Matchs_Events]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Matchs] DROP CONSTRAINT [FK_Matchs_Events];
GO
IF OBJECT_ID(N'[dbo].[FK_Matchs_Teams]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Matchs] DROP CONSTRAINT [FK_Matchs_Teams];
GO
IF OBJECT_ID(N'[dbo].[FK_Ranks_Subscriptions]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Ranks] DROP CONSTRAINT [FK_Ranks_Subscriptions];
GO
IF OBJECT_ID(N'[dbo].[FK_Subscriptions_aspnet_Membership1]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Subscriptions] DROP CONSTRAINT [FK_Subscriptions_aspnet_Membership1];
GO
IF OBJECT_ID(N'[dbo].[FK_Subscriptions_CustomContest]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Subscriptions] DROP CONSTRAINT [FK_Subscriptions_CustomContest];
GO
IF OBJECT_ID(N'[dbo].[FK_UserBets_aspnet_Users]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserBets] DROP CONSTRAINT [FK_UserBets_aspnet_Users];
GO
IF OBJECT_ID(N'[dbo].[FK_UserBets_Matchs]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserBets] DROP CONSTRAINT [FK_UserBets_Matchs];
GO
IF OBJECT_ID(N'[dbo].[FK_UserMailCustomContest_CustomContest]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserMailCustomContest] DROP CONSTRAINT [FK_UserMailCustomContest_CustomContest];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Championships]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Championships];
GO
IF OBJECT_ID(N'[dbo].[Comments]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Comments];
GO
IF OBJECT_ID(N'[dbo].[Contests]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Contests];
GO
IF OBJECT_ID(N'[dbo].[CustomContest]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CustomContest];
GO
IF OBJECT_ID(N'[dbo].[CustomContestLinks]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CustomContestLinks];
GO
IF OBJECT_ID(N'[dbo].[CustomContestSettings]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CustomContestSettings];
GO
IF OBJECT_ID(N'[dbo].[Events]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Events];
GO
IF OBJECT_ID(N'[dbo].[EventScores]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EventScores];
GO
IF OBJECT_ID(N'[dbo].[Matchs]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Matchs];
GO
IF OBJECT_ID(N'[dbo].[Ranks]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Ranks];
GO
IF OBJECT_ID(N'[dbo].[Seasons]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Seasons];
GO
IF OBJECT_ID(N'[dbo].[SettingsParameters]', 'U') IS NOT NULL
    DROP TABLE [dbo].[SettingsParameters];
GO
IF OBJECT_ID(N'[dbo].[Subscriptions]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Subscriptions];
GO
IF OBJECT_ID(N'[dbo].[sysdiagrams]', 'U') IS NOT NULL
    DROP TABLE [dbo].[sysdiagrams];
GO
IF OBJECT_ID(N'[dbo].[Teams]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Teams];
GO
IF OBJECT_ID(N'[dbo].[UserBets]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserBets];
GO
IF OBJECT_ID(N'[dbo].[UserMailCustomContest]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserMailCustomContest];
GO

IF OBJECT_ID(N'[MyBetDBModelStoreContainer].[vw_rank]', 'U') IS NOT NULL
    DROP TABLE [MyBetDBModelStoreContainer].[vw_rank];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Comments'
CREATE TABLE [dbo].[Comments] (
    [CommentId] int IDENTITY(1,1) NOT NULL,
    [CommentDate] datetime  NOT NULL,
    [Width] int  NOT NULL,
    [Height] int  NOT NULL,
    [TournamentId] int  NOT NULL,
    [UserId] uniqueidentifier  NOT NULL,
    [Title] nchar(100)  NULL
);
GO

-- Creating table 'Teams'
CREATE TABLE [dbo].[Teams] (
    [TeamId] int IDENTITY(1,1) NOT NULL,
    [Name] nchar(30)  NOT NULL,
    [Icon] varbinary(max)  NULL
);
GO

-- Creating table 'Championships'
CREATE TABLE [dbo].[Championships] (
    [ChampionshipId] int  NOT NULL,
    [Name] nchar(15)  NOT NULL,
    [Icon] varbinary(max)  NULL
);
GO

-- Creating table 'Matchs'
CREATE TABLE [dbo].[Matchs] (
    [MatchId] int IDENTITY(1,1) NOT NULL,
    [Date] datetime  NOT NULL,
    [TeamHomeId] int  NOT NULL,
    [TeamAwayId] int  NOT NULL,
    [ScoreHome] tinyint  NULL,
    [ScoreAway] tinyint  NULL,
    [EventId] int  NOT NULL,
    [DisplayName] nchar(50)  NULL
);
GO

-- Creating table 'UserBets'
CREATE TABLE [dbo].[UserBets] (
    [UserId] uniqueidentifier  NOT NULL,
    [MatchId] int  NOT NULL,
    [ScoreHome] int  NOT NULL,
    [ScoreAway] int  NOT NULL,
    [Point] int  NULL
);
GO

-- Creating table 'Seasons'
CREATE TABLE [dbo].[Seasons] (
    [SeasonId] int IDENTITY(1,1) NOT NULL,
    [StartYear] int  NOT NULL,
    [EndYear] int  NOT NULL,
    [Display] nchar(30)  NOT NULL
);
GO

-- Creating table 'Events'
CREATE TABLE [dbo].[Events] (
    [EventId] int IDENTITY(1,1) NOT NULL,
    [DayNumber] int  NOT NULL,
    [OpenDate] datetime  NOT NULL,
    [CloseDate] datetime  NOT NULL,
    [ContestId] int  NOT NULL
);
GO

-- Creating table 'Contests'
CREATE TABLE [dbo].[Contests] (
    [ContestId] int IDENTITY(1,1) NOT NULL,
    [ChampionshipId] int  NOT NULL,
    [SeasonId] int  NOT NULL
);
GO

-- Creating table 'CustomContest'
CREATE TABLE [dbo].[CustomContest] (
    [CustomContestId] int IDENTITY(1,1) NOT NULL,
    [AdministratorId] uniqueidentifier  NOT NULL,
    [DisplayName] nchar(255)  NOT NULL,
    [Password] nvarchar(128)  NULL
);
GO

-- Creating table 'CustomContestLinks'
CREATE TABLE [dbo].[CustomContestLinks] (
    [CustomContestLinkId] int IDENTITY(1,1) NOT NULL,
    [ContestId] int  NOT NULL,
    [CustomContestId] int  NOT NULL
);
GO

-- Creating table 'CustomContestSettings'
CREATE TABLE [dbo].[CustomContestSettings] (
    [CustomContestSettingsId] int IDENTITY(1,1) NOT NULL,
    [SettingsParameterId] int  NOT NULL,
    [Value] nchar(50)  NULL,
    [CustomContestId] int  NOT NULL
);
GO

-- Creating table 'Ranks'
CREATE TABLE [dbo].[Ranks] (
    [RankId] int  NOT NULL,
    [TotalScore] bigint  NOT NULL,
    [EventCount] int  NOT NULL,
    [GoodPredictionCount] int  NOT NULL,
    [GoodScoreCount] int  NOT NULL,
    [MatchCount] int  NOT NULL,
    [SubscriptionId] int  NOT NULL,
    [CurrentRank] int  NOT NULL
);
GO

-- Creating table 'SettingsParameters'
CREATE TABLE [dbo].[SettingsParameters] (
    [SettingsParameterId] int IDENTITY(1,1) NOT NULL,
    [Description] nchar(255)  NOT NULL
);
GO

-- Creating table 'Subscriptions'
CREATE TABLE [dbo].[Subscriptions] (
    [SubscriptionId] int IDENTITY(1,1) NOT NULL,
    [UserId] uniqueidentifier  NOT NULL,
    [CustomContestId] int  NOT NULL
);
GO

-- Creating table 'vw_rank'
CREATE TABLE [dbo].[vw_rank] (
    [CustomContestId] int  NOT NULL,
    [TotalScore] bigint  NOT NULL,
    [GoodPredictionCount] int  NOT NULL,
    [GoodScoreCount] int  NOT NULL,
    [EventCount] int  NOT NULL,
    [MatchCount] int  NOT NULL,
    [UserId] uniqueidentifier  NOT NULL,
    [UserName] nvarchar(256)  NOT NULL,
    [CurrentRank] int  NOT NULL
);
GO

-- Creating table 'EventScores'
CREATE TABLE [dbo].[EventScores] (
    [UserId] uniqueidentifier  NOT NULL,
    [EventId] int  NOT NULL,
    [Score] int  NOT NULL
);
GO

-- Creating table 'UserMailCustomContest'
CREATE TABLE [dbo].[UserMailCustomContest] (
    [LoweredUserEmail] nchar(256)  NOT NULL,
    [CustomContestId] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [CommentId] in table 'Comments'
ALTER TABLE [dbo].[Comments]
ADD CONSTRAINT [PK_Comments]
    PRIMARY KEY CLUSTERED ([CommentId] ASC);
GO

-- Creating primary key on [TeamId] in table 'Teams'
ALTER TABLE [dbo].[Teams]
ADD CONSTRAINT [PK_Teams]
    PRIMARY KEY CLUSTERED ([TeamId] ASC);
GO

-- Creating primary key on [ChampionshipId] in table 'Championships'
ALTER TABLE [dbo].[Championships]
ADD CONSTRAINT [PK_Championships]
    PRIMARY KEY CLUSTERED ([ChampionshipId] ASC);
GO

-- Creating primary key on [MatchId] in table 'Matchs'
ALTER TABLE [dbo].[Matchs]
ADD CONSTRAINT [PK_Matchs]
    PRIMARY KEY CLUSTERED ([MatchId] ASC);
GO

-- Creating primary key on [UserId], [MatchId] in table 'UserBets'
ALTER TABLE [dbo].[UserBets]
ADD CONSTRAINT [PK_UserBets]
    PRIMARY KEY CLUSTERED ([UserId], [MatchId] ASC);
GO

-- Creating primary key on [SeasonId] in table 'Seasons'
ALTER TABLE [dbo].[Seasons]
ADD CONSTRAINT [PK_Seasons]
    PRIMARY KEY CLUSTERED ([SeasonId] ASC);
GO

-- Creating primary key on [EventId] in table 'Events'
ALTER TABLE [dbo].[Events]
ADD CONSTRAINT [PK_Events]
    PRIMARY KEY CLUSTERED ([EventId] ASC);
GO

-- Creating primary key on [ContestId] in table 'Contests'
ALTER TABLE [dbo].[Contests]
ADD CONSTRAINT [PK_Contests]
    PRIMARY KEY CLUSTERED ([ContestId] ASC);
GO

-- Creating primary key on [CustomContestId] in table 'CustomContest'
ALTER TABLE [dbo].[CustomContest]
ADD CONSTRAINT [PK_CustomContest]
    PRIMARY KEY CLUSTERED ([CustomContestId] ASC);
GO

-- Creating primary key on [CustomContestLinkId] in table 'CustomContestLinks'
ALTER TABLE [dbo].[CustomContestLinks]
ADD CONSTRAINT [PK_CustomContestLinks]
    PRIMARY KEY CLUSTERED ([CustomContestLinkId] ASC);
GO

-- Creating primary key on [CustomContestSettingsId] in table 'CustomContestSettings'
ALTER TABLE [dbo].[CustomContestSettings]
ADD CONSTRAINT [PK_CustomContestSettings]
    PRIMARY KEY CLUSTERED ([CustomContestSettingsId] ASC);
GO

-- Creating primary key on [RankId] in table 'Ranks'
ALTER TABLE [dbo].[Ranks]
ADD CONSTRAINT [PK_Ranks]
    PRIMARY KEY CLUSTERED ([RankId] ASC);
GO

-- Creating primary key on [SettingsParameterId] in table 'SettingsParameters'
ALTER TABLE [dbo].[SettingsParameters]
ADD CONSTRAINT [PK_SettingsParameters]
    PRIMARY KEY CLUSTERED ([SettingsParameterId] ASC);
GO

-- Creating primary key on [SubscriptionId] in table 'Subscriptions'
ALTER TABLE [dbo].[Subscriptions]
ADD CONSTRAINT [PK_Subscriptions]
    PRIMARY KEY CLUSTERED ([SubscriptionId] ASC);
GO

-- Creating primary key on [CustomContestId], [TotalScore], [GoodPredictionCount], [GoodScoreCount], [EventCount], [MatchCount], [UserId], [UserName], [CurrentRank] in table 'vw_rank'
ALTER TABLE [dbo].[vw_rank]
ADD CONSTRAINT [PK_vw_rank]
    PRIMARY KEY CLUSTERED ([CustomContestId], [TotalScore], [GoodPredictionCount], [GoodScoreCount], [EventCount], [MatchCount], [UserId], [UserName], [CurrentRank] ASC);
GO

-- Creating primary key on [UserId], [EventId] in table 'EventScores'
ALTER TABLE [dbo].[EventScores]
ADD CONSTRAINT [PK_EventScores]
    PRIMARY KEY CLUSTERED ([UserId], [EventId] ASC);
GO

-- Creating primary key on [LoweredUserEmail], [CustomContestId] in table 'UserMailCustomContest'
ALTER TABLE [dbo].[UserMailCustomContest]
ADD CONSTRAINT [PK_UserMailCustomContest]
    PRIMARY KEY CLUSTERED ([LoweredUserEmail], [CustomContestId] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [UserId] in table 'Comments'
ALTER TABLE [dbo].[Comments]
ADD CONSTRAINT [FK_Comments_aspnet_Users]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[aspnet_Users]
        ([UserId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Comments_aspnet_Users'
CREATE INDEX [IX_FK_Comments_aspnet_Users]
ON [dbo].[Comments]
    ([UserId]);
GO

-- Creating foreign key on [TeamAwayId] in table 'Matchs'
ALTER TABLE [dbo].[Matchs]
ADD CONSTRAINT [FK_Matchs_ChampionshipDays1]
    FOREIGN KEY ([TeamAwayId])
    REFERENCES [dbo].[Teams]
        ([TeamId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Matchs_ChampionshipDays1'
CREATE INDEX [IX_FK_Matchs_ChampionshipDays1]
ON [dbo].[Matchs]
    ([TeamAwayId]);
GO

-- Creating foreign key on [TeamHomeId] in table 'Matchs'
ALTER TABLE [dbo].[Matchs]
ADD CONSTRAINT [FK_Matchs_Teams]
    FOREIGN KEY ([TeamHomeId])
    REFERENCES [dbo].[Teams]
        ([TeamId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Matchs_Teams'
CREATE INDEX [IX_FK_Matchs_Teams]
ON [dbo].[Matchs]
    ([TeamHomeId]);
GO

-- Creating foreign key on [UserId] in table 'UserBets'
ALTER TABLE [dbo].[UserBets]
ADD CONSTRAINT [FK_UserBets_aspnet_Users]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[aspnet_Users]
        ([UserId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [MatchId] in table 'UserBets'
ALTER TABLE [dbo].[UserBets]
ADD CONSTRAINT [FK_UserBets_Matchs]
    FOREIGN KEY ([MatchId])
    REFERENCES [dbo].[Matchs]
        ([MatchId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserBets_Matchs'
CREATE INDEX [IX_FK_UserBets_Matchs]
ON [dbo].[UserBets]
    ([MatchId]);
GO

-- Creating foreign key on [EventId] in table 'Matchs'
ALTER TABLE [dbo].[Matchs]
ADD CONSTRAINT [FK_Matchs_Events]
    FOREIGN KEY ([EventId])
    REFERENCES [dbo].[Events]
        ([EventId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Matchs_Events'
CREATE INDEX [IX_FK_Matchs_Events]
ON [dbo].[Matchs]
    ([EventId]);
GO

-- Creating foreign key on [ChampionshipId] in table 'Contests'
ALTER TABLE [dbo].[Contests]
ADD CONSTRAINT [FK_Contests_Championships]
    FOREIGN KEY ([ChampionshipId])
    REFERENCES [dbo].[Championships]
        ([ChampionshipId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Contests_Championships'
CREATE INDEX [IX_FK_Contests_Championships]
ON [dbo].[Contests]
    ([ChampionshipId]);
GO

-- Creating foreign key on [SeasonId] in table 'Contests'
ALTER TABLE [dbo].[Contests]
ADD CONSTRAINT [FK_Contests_Seasons]
    FOREIGN KEY ([SeasonId])
    REFERENCES [dbo].[Seasons]
        ([SeasonId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Contests_Seasons'
CREATE INDEX [IX_FK_Contests_Seasons]
ON [dbo].[Contests]
    ([SeasonId]);
GO

-- Creating foreign key on [ContestId] in table 'Events'
ALTER TABLE [dbo].[Events]
ADD CONSTRAINT [FK_Events_Contests]
    FOREIGN KEY ([ContestId])
    REFERENCES [dbo].[Contests]
        ([ContestId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Events_Contests'
CREATE INDEX [IX_FK_Events_Contests]
ON [dbo].[Events]
    ([ContestId]);
GO

-- Creating foreign key on [AdministratorId] in table 'CustomContest'
ALTER TABLE [dbo].[CustomContest]
ADD CONSTRAINT [FK_CustomContest_aspnet_Membership]
    FOREIGN KEY ([AdministratorId])
    REFERENCES [dbo].[aspnet_Membership]
        ([UserId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CustomContest_aspnet_Membership'
CREATE INDEX [IX_FK_CustomContest_aspnet_Membership]
ON [dbo].[CustomContest]
    ([AdministratorId]);
GO

-- Creating foreign key on [UserId] in table 'Subscriptions'
ALTER TABLE [dbo].[Subscriptions]
ADD CONSTRAINT [FK_Subscriptions_aspnet_Membership]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[aspnet_Membership]
        ([UserId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Subscriptions_aspnet_Membership'
CREATE INDEX [IX_FK_Subscriptions_aspnet_Membership]
ON [dbo].[Subscriptions]
    ([UserId]);
GO

-- Creating foreign key on [ContestId] in table 'CustomContestLinks'
ALTER TABLE [dbo].[CustomContestLinks]
ADD CONSTRAINT [FK_CustomContestLinks_Contests]
    FOREIGN KEY ([ContestId])
    REFERENCES [dbo].[Contests]
        ([ContestId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CustomContestLinks_Contests'
CREATE INDEX [IX_FK_CustomContestLinks_Contests]
ON [dbo].[CustomContestLinks]
    ([ContestId]);
GO

-- Creating foreign key on [CustomContestId] in table 'CustomContestLinks'
ALTER TABLE [dbo].[CustomContestLinks]
ADD CONSTRAINT [FK_CustomContestLinks_CustomContest]
    FOREIGN KEY ([CustomContestId])
    REFERENCES [dbo].[CustomContest]
        ([CustomContestId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CustomContestLinks_CustomContest'
CREATE INDEX [IX_FK_CustomContestLinks_CustomContest]
ON [dbo].[CustomContestLinks]
    ([CustomContestId]);
GO

-- Creating foreign key on [CustomContestId] in table 'CustomContestSettings'
ALTER TABLE [dbo].[CustomContestSettings]
ADD CONSTRAINT [FK_CustomContestSettings_CustomContest]
    FOREIGN KEY ([CustomContestId])
    REFERENCES [dbo].[CustomContest]
        ([CustomContestId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CustomContestSettings_CustomContest'
CREATE INDEX [IX_FK_CustomContestSettings_CustomContest]
ON [dbo].[CustomContestSettings]
    ([CustomContestId]);
GO

-- Creating foreign key on [SubscriptionId] in table 'Ranks'
ALTER TABLE [dbo].[Ranks]
ADD CONSTRAINT [FK_Ranks_Subscriptions]
    FOREIGN KEY ([SubscriptionId])
    REFERENCES [dbo].[Subscriptions]
        ([SubscriptionId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Ranks_Subscriptions'
CREATE INDEX [IX_FK_Ranks_Subscriptions]
ON [dbo].[Ranks]
    ([SubscriptionId]);
GO

-- Creating foreign key on [SettingsParameterId] in table 'CustomContestSettings'
ALTER TABLE [dbo].[CustomContestSettings]
ADD CONSTRAINT [FK_CustomContestSettings_SettingsParameters]
    FOREIGN KEY ([SettingsParameterId])
    REFERENCES [dbo].[SettingsParameters]
        ([SettingsParameterId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CustomContestSettings_SettingsParameters'
CREATE INDEX [IX_FK_CustomContestSettings_SettingsParameters]
ON [dbo].[CustomContestSettings]
    ([SettingsParameterId]);
GO

-- Creating foreign key on [CustomContestId] in table 'Subscriptions'
ALTER TABLE [dbo].[Subscriptions]
ADD CONSTRAINT [FK_Subscriptions_CustomContest]
    FOREIGN KEY ([CustomContestId])
    REFERENCES [dbo].[CustomContest]
        ([CustomContestId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Subscriptions_CustomContest'
CREATE INDEX [IX_FK_Subscriptions_CustomContest]
ON [dbo].[Subscriptions]
    ([CustomContestId]);
GO

-- Creating foreign key on [AdministratorId] in table 'CustomContest'
ALTER TABLE [dbo].[CustomContest]
ADD CONSTRAINT [FK_CustomContest_aspnet_Membership1]
    FOREIGN KEY ([AdministratorId])
    REFERENCES [dbo].[aspnet_Users]
        ([UserId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CustomContest_aspnet_Membership1'
CREATE INDEX [IX_FK_CustomContest_aspnet_Membership1]
ON [dbo].[CustomContest]
    ([AdministratorId]);
GO

-- Creating foreign key on [UserId] in table 'Subscriptions'
ALTER TABLE [dbo].[Subscriptions]
ADD CONSTRAINT [FK_Subscriptions_aspnet_Membership1]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[aspnet_Users]
        ([UserId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Subscriptions_aspnet_Membership1'
CREATE INDEX [IX_FK_Subscriptions_aspnet_Membership1]
ON [dbo].[Subscriptions]
    ([UserId]);
GO

-- Creating foreign key on [UserId] in table 'EventScores'
ALTER TABLE [dbo].[EventScores]
ADD CONSTRAINT [FK_EventScores_aspnet_Users]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[aspnet_Users]
        ([UserId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [EventId] in table 'EventScores'
ALTER TABLE [dbo].[EventScores]
ADD CONSTRAINT [FK_EventScores_Events]
    FOREIGN KEY ([EventId])
    REFERENCES [dbo].[Events]
        ([EventId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EventScores_Events'
CREATE INDEX [IX_FK_EventScores_Events]
ON [dbo].[EventScores]
    ([EventId]);
GO

-- Creating foreign key on [CustomContestId] in table 'UserMailCustomContest'
ALTER TABLE [dbo].[UserMailCustomContest]
ADD CONSTRAINT [FK_UserMailCustomContest_CustomContest]
    FOREIGN KEY ([CustomContestId])
    REFERENCES [dbo].[CustomContest]
        ([CustomContestId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserMailCustomContest_CustomContest'
CREATE INDEX [IX_FK_UserMailCustomContest_CustomContest]
ON [dbo].[UserMailCustomContest]
    ([CustomContestId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------